package com.hellpro.lolbox.video.view.fragment.view;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.base.BaseFragment;
import com.hellpro.lolbox.config.UrlConfigs;
import com.hellpro.lolbox.video.bean.VideoManitoBean;
import com.hellpro.lolbox.video.presenter.VideoPresenter;
import com.hellpro.lolbox.video.view.fragment.IManitoFragment;

import java.util.List;

import butterknife.BindView;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/19
 * 备注:大神直播间
 */
public class ManitoFragment extends BaseFragment implements IManitoFragment {


    @BindView(R.id.manito_refresh_lv)
    PullToRefreshListView mLv;
    private VideoPresenter presenter;
    private List<VideoManitoBean> data;
    //使用Handler回调数据
    private Handler mHandler = new Handler() {


        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                data = (List<VideoManitoBean>) msg.obj;
                presenter.setManitoAdapter(data, mLv, getActivity());
            }
        }
    };


    @Override
    public void initView() {
        presenter = new VideoPresenter(this, getActivity(), mHandler);
        presenter.setMantioInfo();
        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                presenter.setManitoLiatener(data, parent, view, position);
            }
        });
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_manito;
    }

    @Override
    public PullToRefreshListView getPullToRefreshListView() {
        return mLv;
    }

    @Override
    public String getManitoUrl() {
        return UrlConfigs.ViDEO_MONITO_PATH;
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
